﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PwdMgr.Utility
{
    public static class Extension
    {
        public unsafe static bool ByteSequenceEqual(this byte[] first,
            byte[] second, int count)
        {
            ThrowUtil.ArgumentNullException(first, "first");
            ThrowUtil.ArgumentNullException(second, "second");

            if (count <= 0)
                throw new ArgumentOutOfRangeException("count should be greater than zero.");

            if (first.Length < count || second.Length < count)
                return false;

            int i = 0;
            fixed (byte* f = first)
            {
                fixed (byte* s = second)
                {
                    while (i < count)
                    {
                        if(*(f + i) != *(s + i))
                            return false;
                        i++;
                    }
                }
            }

            return true;
        }
    }
}
